package com.xoa.controller.inv;


import com.xoa.model.inv.PoCommodityOut;
import com.xoa.service.inv.PoCommodityOutService;
import com.xoa.util.ToJson;
import com.xoa.util.page.PageParams;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 商品出库管理
 */
@Controller
@RequestMapping("/poCommodityOut")
public class PoCommodityOutController {

    @Resource
    private PoCommodityOutService poCommodityOutService;


    //处理时间  将前台传过来的时间存到数据库中
    //方法描述 : 使用@InitBinder 标签对表单数据绑定
    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
    }
    /**
     * 新建商品出库信息接口
     * @param request
     * @param poCommodityOut
     * @return
     */
    @ResponseBody
    @RequestMapping("/insertProductOut")
    public ToJson<PoCommodityOut> insertProduct(HttpServletRequest request, PoCommodityOut poCommodityOut){
        return poCommodityOutService.insertProductOut(request,poCommodityOut);
    }

    /**
     * 修改商品出库信息接口
     * @param request
     * @param poCommodityOut
     * @return
     */
    @ResponseBody
    @RequestMapping("/updateProductOut")
    public ToJson<PoCommodityOut> updateProduct(HttpServletRequest request,PoCommodityOut poCommodityOut){
        return poCommodityOutService.updateProduct(request,poCommodityOut);
    }

    /**
     * 查询商品详情信息
     * @param request
     * @param retreatId
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectProductOutById")
    public ToJson<PoCommodityOut> selectProductById(HttpServletRequest request,Integer retreatId){
        return poCommodityOutService.selectProductById(request,retreatId);
    }

    /**
     * 根据商品大类查询商品详情信息
     * @param request
     * @param typeId
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectProductOutByTypeId")
    public ToJson<PoCommodityOut> selectProductOutByTypeId(HttpServletRequest request,String typeId){
        return poCommodityOutService.selectProductOutByTypeId(request,typeId);
    }

    /**
     * 删除商品信息
     * @param request
     * @param retreatId
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteProductOutById")
    public ToJson<PoCommodityOut> deleteProductById(HttpServletRequest request,Integer retreatId){
        return poCommodityOutService.deleteProductById(request,retreatId);
    }

    /**
     * 条件查询仓库信息
     * @param request
     * @param poCommodityOut
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectProductOutInfo")
    public ToJson<PoCommodityOut> selectProductInfo(HttpServletRequest request,PoCommodityOut poCommodityOut,Integer page, Integer pageSize){
        return poCommodityOutService.selectProductInfo(request,poCommodityOut,page,pageSize);
    }


    /**
     * 多条件查询数据
     * @param request
     * @param poCommodityOut
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectAll")
    public ToJson<PoCommodityOut> selectAll(HttpServletRequest request,Integer page, Integer pageSize, boolean useFlag,PoCommodityOut poCommodityOut, Integer type){
        ToJson json = new ToJson<PoCommodityOut>(1, "err");
        Map<String, Object> map = new HashMap<String, Object>();
        PageParams pageParams = new PageParams();
        pageParams.setUseFlag(useFlag);
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        map.put("type", type);
        map.put("obj", poCommodityOut);
        map.put("page", pageParams);
        return poCommodityOutService.selectAll(map);
    }
}
